public class Test4 {



    public static void main4(String[] args) throws InterruptedException {
        // 创建三个线程
        Thread tc = new Thread(() -> {
            // 打印c
            System.out.print(Thread.currentThread().getName() + " ");
        }, "c");

        Thread tb = new Thread(() -> {
            try {
                // 等待c 执行完成
                tc.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            // 打印b
            System.out.print(Thread.currentThread().getName() + " ");
        }, "b");

        Thread ta = new Thread(() -> {
            try {
                // 等待b 执行完成
                tb.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            // 打印a
            System.out.print(Thread.currentThread().getName() + " ");
        }, "a");

        // 需要让他们同时启动，并按 c，b，a的顺序打印
        ta.start();
        tb.start();
        tc.start();
    }
    public static void main(String[] args) {
        Thread c = new Thread(()->{

            System.out.println("c:"+Thread.currentThread().getName());

        },"c");
        Thread b = new Thread(()->{
            try {
                c.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("b:"+Thread.currentThread().getName());

        },"b");
        Thread a = new Thread(()->{
            try {
                b.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("a:"+Thread.currentThread().getName());
            //System.out.println(a);
        },"a");


        a.start();
        b.start();
        c.start();
    }
    public static void main2(String[] args) throws InterruptedException {
        //打印C的线程里面，嵌套一个B，B里面嵌套A.

        for (int i = 0; i < 10; i++) {
            Thread t3 = new Thread(()->{
                Thread t2 = new Thread(()->{
                    Thread t1 = new Thread(()->{
                        System.out.print("A");
                    });
                    t1.start();
                    try {
                        t1.join();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    System.out.print("B");
                });
                t2.start();
                try {
                    t2.join();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("C");
            });
            t3.start();
            Thread.sleep(500);
        }

    }
    public static void main1(String[] args) throws InterruptedException {
        for (int i = 0; i < 10; i++) {
            Thread t3 = new Thread(()->{
                System.out.print("A");

                Thread t2 = new Thread(()->{
                    System.out.print("B");
                    Thread t1 = new Thread(()->{

                        System.out.println("C");


                    });
                    t1.start();
                });
                t2.start();
                try {
                    t2.join();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            });
            t3.start();
            Thread.sleep(500);
        }

    }
}
